<template>
  <el-dialog
      :model-value="dialogVisible"
      :title="props.dialogNsTitle"
      width="35%"
      @close="handleClose"
  >
    <el-form size="default" :model="form" ref="formRef" label-width="130px" :rules="rules" label-position="left" >
      <el-form-item label="产地名称" prop="cdmc">
        <el-select v-model="form.cdmc" clearable placeholder="请选择">
          <el-option
              v-for="(item, index) in chandiName"
              :key="index"
              :label="item"
              :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="农事作业" prop="nszy">
        <el-input v-model="form.nszy" clearable/>
      </el-form-item>
      <el-form-item label="作业人" prop="zyr">
        <el-input v-model="form.zyr" clearable/>
      </el-form-item>
      <el-form-item label="投入品名称" prop="trpmc">
        <el-input v-model="form.trpmc" clearable/>
      </el-form-item>
      <el-form-item label="作业量" prop="zyl">
        <el-input v-model="form.zyl" clearable/>
      </el-form-item>
      <el-form-item label="单位" prop="zyldw">
        <el-input v-model="form.zyldw" clearable/>
      </el-form-item>
      <el-form-item label="采购日期" prop="rq">
        <el-date-picker
            v-model="form.rq"
            type="date"
            placeholder="选择日期"
            :size="'default'"
            clearable
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">
          确认
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {defineEmits, ref, defineProps, watch, onMounted} from 'vue'
import {getOptionsInfo} from "@/api/methods/initInfo.js";
import {getAllCdmc} from "@/api/apiPath/twoPart.js";

const props = defineProps({
  dialogNsTitle: {
    type: String,
    default: '',
    required: true
  },
  dialogNsTableValue: {
    type: Object,
    default: {}
  },
  queryForm: {
  },
  dialogVisible: {
    type: Boolean,
    default: false
  }
})
const chandiName = ref([])
const formRef = ref(null)
const form = ref({
  qydm: '',
  zyr: '',
  trpmc: '',
  zyldw: '',
  zyl: '',
  nszy: '',
  cdmc: '',
  rq: '',
})
onMounted( ()=> {
  getOptionsInfo(getAllCdmc(), chandiName)
  form.value = props.dialogNsTableValue
})


const rules = ref({
  cdmc: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  zyl: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
})
const emits = defineEmits(['update:modelValue', 'handleConfirm'])
const handleClose = ()=> {
  emits('update:modelValue', false)
}
const handleConfirm = () => {
  emits("handleConfirm", {...form.value}, {...formRef.value})
}
</script>

<style scoped>


</style>